package com.service.impl;


import com.controller.respdto.config.PermissionList;
import com.enums.CommonEnum;
import com.repository.mapper.AuthConfigMapper;
import com.repository.po.AuthConfig;
import com.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Ruiwen
 * @since 2024-11-19
 */
@Service
public class ConfigServiceImpl implements ConfigService {

    @Resource
    AuthConfigMapper authConfigMapper;

    @Override
    public PermissionList getPermissionList() {
        return PermissionList.builder().permissionList(authConfigMapper.selectList(null)).build();
    }

    @Override
    public Boolean updatePermissionSwitch(Integer authId) {
        AuthConfig authConfig = authConfigMapper.selectById(authId);
        if (Objects.isNull(authConfig)) {
            throw new RuntimeException("权限菜单不存在");
        }
        Integer updateStatus = Objects.equals(authConfig.getIsShow(), CommonEnum.SHOW_BUTTON.getCode()) ? CommonEnum.NOT_SHOW_BUTTON.getCode() : CommonEnum.SHOW_BUTTON.getCode();
        AuthConfig updateAuthConfig = new AuthConfig();
        updateAuthConfig.setId(authConfig.getId());
        updateAuthConfig.setIsShow(updateStatus);
        return authConfigMapper.updateById(updateAuthConfig) > 0;

    }
}
